import pathToRegexp from 'path-to-regexp/index';
import {getPointplan,postPointplan,deletePointplan,putPointplan,getMaillist,getPoint} from 'services/app';
export default {
    namespace: 'pointplan',
    state: {
        pages:1,
        record:{},
    },
    subscriptions: {
        setupHistory ({ dispatch, history }) {
            history.listen((location) => {
                const match = pathToRegexp('/home').exec(location.pathname);
            });
        },
        setup ({ dispatch }) {},
    },
    effects: {
        //查看登录状态
        *getPointplan ({ payload }, { call, put }){
            const {data,total} = yield call(getPointplan, payload);
            yield put({ type: 'save', payload: {getPointplanData:data,total:total,pages:payload.pageNumber}});
        },
        //添加巡检计划
        *postPointplan ({ payload }, { call, put }){
            const data= yield call(postPointplan, payload);
            if(data.code == 0){
                yield put({ type: 'save', payload: {pages:0,view:false}});
            }
        },
        *newpost ({ payload }, { call, put }){
            const data = yield call(getMaillist, {
                name:"",
                phone :"",
                pageNumber :0,
                pageSize :0,
            });
            const dataTow = yield call(getPoint, {
                route_name: "",
                route_num :"",
                duty_name:"",
                pageNumber :0,
                pageSize :0,
            });

            yield put({ type: 'save', payload: {FZR:data.data,XJLX:dataTow.data}});
        },
        //删除巡检计划
        *deletePointplan ({ payload }, { call, put }){
            const data= yield call(deletePointplan, payload);
            if(data.code == 0){
                yield put({ type: 'save', payload: {pages:0}});
            }
        },
        //修改巡检计划
        *putPointplan ({ payload }, { call, put }){
            const data= yield call(putPointplan, payload);
            if(data.code == 0){
                yield put({ type: 'save', payload: {pages:0,view:false}});
            }
        },
        //输入输出
        *inputOut ({ payload }, { put }){
            yield put({ type: 'save', payload: payload });
        },
    },
    reducers: {
        save (state, { payload }) {
            return { ...state, ...payload };
        },
    },
};
